# ===============================================================
# 
# Release under GPLv-3.0.
# 
# @file    Makefile
# @brief   
# @author  gnsyxiang <gnsyxiang@163.com>
# @date    02/06 2021 10:12
# @version v0.0.1
# 
# @since    note
# @note     note
# 
#     change log:
#     NO.     Author              Date            Modified
#     00      zhenquan.qiu        02/06 2021      create the file
# 
#     last modified: 02/06 2021 10:12
# ===============================================================

ifndef top_dir
top_dir := $(shell pwd)/../../..
endif

project                 := protobuf
project_version         := 3.21.12
project_download_url    := https://codeload.github.com/protocolbuffers/protobuf/tar.gz/refs/tags/v$(project_version)

include $(top_dir)/configs/common_var.mk

all: depend_lib $(target_dir)-make

include $(sub_target_path)/common_sub_target.mk

depend_lib: check_zlib

$(target_dir)-config: $(target_dir)-rename-gz-src
ifneq ($(config_ok_mark_path), $(wildcard $(config_ok_mark_path)))
	$(MKDIR) $(build_path)/$(@:-config=)

	cd $(src_path)/$(@:-config=) && \
        ./autogen.sh

	case $(host) in                                         \
        x86*)                                               \
            cd $(build_path)/$(@:-config=) &&               \
            $(src_path)/$(@:-config=)/configure             \
            CC=$(GCC) CXX=$(CXX)                            \
            CPPFLAGS="$(cppflags_com) -Wno-error=stringop-overflow=" \
            CFLAGS="$(cflags_com)"                          \
            CXXFLAGS="$(cxxflags_com)"                      \
            LDFLAGS="$(ldflags_com)"                        \
            LIBS="$(libs_com)"                              \
            PKG_CONFIG_PATH="$(pkg_config_path)"            \
            --program-suffix=                               \
            --prefix=$(prefix_path)                         \
            --build=$(build)                                \
            --host=$(host)                                  \
            --target=$(host)                                \
                                                            \
            --with-zlib                                     \
        ;;                                                  \
        arm-*|aarch*)                                       \
            cd $(build_path)/$(@:-config=) &&               \
            $(src_path)/$(@:-config=)/configure             \
            CC=$(GCC) CXX=$(CXX)                            \
            CPPFLAGS="$(cppflags_com)"                      \
            CFLAGS="$(cflags_com)"                          \
            CXXFLAGS="$(cxxflags_com)"                      \
            LDFLAGS="$(ldflags_com)"                        \
            LIBS="$(libs_com)"                              \
            PKG_CONFIG_PATH="$(pkg_config_path)"            \
            --with-protoc=/mnt/nfs/pc/ubuntu/bin/protoc     \
            --program-suffix=                               \
            --prefix=$(prefix_path)                         \
            --build=$(build)                                \
            --host=$(host)                                  \
            --target=$(host)                                \
                                                            \
            --with-zlib                                     \
        ;;                                                  \
    esac

	$(TOUCH) $(config_ok_mark_path)
endif

.PHONY: demo all clean distclean list

